<?php
//产品分类列表
function classList(){
	$pageSize=$_POST['pageSize'];
	$page=$_POST['curPage']?$_POST['curPage']:1;
	$startCount=($page-1)*$pageSize;
	$sql="select id,cName,cImg,serial,state from cate LIMIT $startCount,$pageSize";
	$row=fetchAll($sql);
	$sqls="select * from cate";
	$rowNum=getResultNum($sqls);
	$arr=array("success"=>true,"totalRows"=>$rowNum,"curPage"=>$page,'data'=>$row);
	echo json_encode($arr);
}
//添加商品分类  
function cLassAdd(){
	$arr=$_POST;
	if(!empty($_FILES['fileImg']['name'])){
		$info=uploadFile("../admin/uploadimg/cate");
		$arr['cImg']=$info[0]['name'];
	}
	if(insert("cate",$arr)){
		$msg="添加成功";
	}else{
		$msg="添加失败";
	}
	return $msg;
}
//编辑商品分类
function cLassEdit(){
	$id=$_REQUEST['id'];
	$arr=$_POST;
	if(!empty($_FILES['fileImg']['name'])){
		$info=uploadFile("../admin/uploadimg/cate");
		$arr['cImg']=$info[0]['name'];
	}
	if(update("cate",$arr,"id=$id")){
		$msg="修改成功";
	}else{
		$msg="修改失败";
	}
	return $msg;
}
//删除产品分类
function classDel(){
	$id=$_POST['id'];
	if(delete("cate","id=$id")){
		$result = array('Success' => true, 'Msg' => '删除成功');
	}else{
		$result = array('Success' => false, 'Msg' => '删除失败');
	}
	echo json_encode($result);
}